<?php
/**
 * Author: Silent Night
 * email: silentwolf_wp@163.com
 * Date: 2017/10/10
 * Time: 11:02
 */

namespace app\admin\model;

use think\Model;
use think;

class Group extends Model
{


    public function getID($pid)
    {
        $data = array();
        $res = $this->where(['id' => $pid])
            ->find();
        if ($res) {
            $data = $res->toArray();
        }
        return $data;
    }

    public function lists($w, $pagesize = "10")
    {
        $rdata = array();
        if (!empty($w))
            $this->where($w);
        $this->order("type", "asc");
        $list = $this->paginate($pagesize)->toArray();
//           echo $this->getLastSql();
        return $list;
    }

    public function getDataForWhere($w)
    {
        $data = array();
        $res = $this->where($w)
            ->find();
        if ($res) {
            $data = $res->toArray();
        }
        return $data;
    }

    public function getDataForWheres($w)
    {
        $data = array();
        $res = $this->where($w)
            ->select();
        if ($res) {
            $data = $res->toArray();
        }
        return $data;
    }

    public function getGroupList($orderby="type asc")
    {
        $data = array();
        $res = $this->order($orderby)
            ->select();
        if ($res) {
            $data = $res->toArray();
        }
        return $data;
    }


    public function updateData($update, $id)
    {
        $res = $this->save($update, ['id' => $id]);
        return $res;
    }

    public function updateDataForArr($update, $where)
    {
        $res = $this->save($update, $where);
        return $res;
    }

    public function updateDataForWhere($update, $where)
    {
        $res = $this->save($update, $where);
        return $res;
    }


    public function add($array)
    {
        $this->save($array);
        return $this->getLastInsID();
    }


    public function delData($w)
    {

        return $this->where($w)->delete();
    }

}